<?php
namespace Admin\Model;

use Think\Model;
use Think\Page;

class BookModel extends Model{
//     protected $_validate = array(
//         array('name', 'require', '行为标识必须', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
//         array('name', '/^[a-zA-Z]\w{0,39}$/', '标识不合法', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
//         array('name', '', '标识已经存在', self::MUST_VALIDATE, 'unique', self::MODEL_BOTH),
//         array('title', 'require', '标题不能为空', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
//         array('title', '1,80', '标题长度不能超过80个字符', self::MUST_VALIDATE, 'length', self::MODEL_BOTH),
//         array('remark', 'require', '行为描述不能为空', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
//         array('remark', '1,140', '行为描述不能超过140个字符', self::MUST_VALIDATE, 'length', self::MODEL_BOTH),
//     );

    
       public function getCata($type){
              $map['parent_id']=$type;
              $page=$this->get_page($map,'category');
              $result['show']=$page->show();
              $result['list']=M('category')->where($map)->limit($page->firstRow.','.$page->listRows)->select();
              return   $result;
          }
     
    
     public function get_page($map,$table_q='Book'){
               
              $count      = M($table_q)->where($map)->count();// 查询满足要求的总记录数
              $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(1)
              $Page -> setConfig('prev','上一页');
              $Page -> setConfig('next','下一页');
              $Page->setConfig('theme', ' %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER% ');
              return $Page;
               
          }
          
          
    
}
?>